﻿using System;
using UnityEngine;

// Token: 0x02000361 RID: 865
public class SimpleFade : MonoBehaviour
{
	// Token: 0x17000223 RID: 547
	// (get) Token: 0x06001592 RID: 5522 RVA: 0x000927C0 File Offset: 0x000909C0
	public bool IsFadeNow
	{
		get
		{
			return this._Fade == SimpleFade.Fade.In || !this.IsEnd;
		}
	}

	// Token: 0x17000224 RID: 548
	// (get) Token: 0x06001593 RID: 5523 RVA: 0x000927DC File Offset: 0x000909DC
	public bool IsEnd
	{
		get
		{
			return this.timer == this._Time && this.fadeInOut == null;
		}
	}

	// Token: 0x06001594 RID: 5524 RVA: 0x000927FC File Offset: 0x000909FC
	public void FadeSet(SimpleFade.Fade fade, float time = -1f, Texture2D tex = null)
	{
		this._Fade = fade;
		if (time != -1f)
		{
			this._Time = time;
		}
		if (tex != null)
		{
			this._Texture = tex;
		}
		this.Init();
	}

	// Token: 0x06001595 RID: 5525 RVA: 0x00092830 File Offset: 0x00090A30
	public void FadeInOutSet(SimpleFade.FadeInOut set, Texture2D tex = null)
	{
		if (tex != null)
		{
			this._Texture = tex;
		}
		this.FadeInOutStart(set);
		this.Init();
	}

	// Token: 0x06001596 RID: 5526 RVA: 0x00092854 File Offset: 0x00090A54
	public void Init()
	{
		this.timer = 0f;
		this._Color.a = (float)((this._Fade != SimpleFade.Fade.In) ? 1 : 0);
		if (this._Texture == null)
		{
			this._Texture = Texture2D.whiteTexture;
		}
	}

	// Token: 0x06001597 RID: 5527 RVA: 0x000928A8 File Offset: 0x00090AA8
	public void ForceEnd()
	{
		this.timer = this._Time;
		this._Color.a = (float)((this._Fade != SimpleFade.Fade.In) ? 0 : 1);
	}

	// Token: 0x06001598 RID: 5528 RVA: 0x000928D4 File Offset: 0x00090AD4
	private void FadeInOutStart(SimpleFade.FadeInOut set)
	{
		if (set != null)
		{
			this.fadeInOut = set;
		}
		if (this.fadeInOut == null)
		{
			return;
		}
		this._Fade = ((set == null) ? SimpleFade.Fade.Out : SimpleFade.Fade.In);
		this._Time = ((set == null) ? this.fadeInOut.outTime : this.fadeInOut.inTime);
		this._Color = ((set == null) ? this.fadeInOut.outColor : this.fadeInOut.inColor);
		this.fadeInOut = set;
		this.Init();
	}

	// Token: 0x06001599 RID: 5529 RVA: 0x00092968 File Offset: 0x00090B68
	protected virtual void Awake()
	{
		this.ForceEnd();
	}

	// Token: 0x0600159A RID: 5530 RVA: 0x00092970 File Offset: 0x00090B70
	protected virtual void Update()
	{
		float a = (float)((this._Fade != SimpleFade.Fade.In) ? 1 : 0);
		float b = (float)((this._Fade != SimpleFade.Fade.In) ? 0 : 1);
		this.timer = Mathf.Min(this.timer + Time.unscaledDeltaTime, this._Time);
		if (this.fadeInOut != null && this.timer == this._Time && this.fadeInOut.Update())
		{
			this.FadeInOutStart(null);
		}
		else
		{
			this._Color.a = Mathf.Lerp(a, b, Mathf.InverseLerp(0f, this._Time, this.timer));
		}
	}

	// Token: 0x0600159B RID: 5531 RVA: 0x00092A24 File Offset: 0x00090C24
	protected virtual void OnGUI()
	{
		if (this._Texture == null)
		{
			return;
		}
		GUI.color = this._Color;
		GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), this._Texture);
	}

	// Token: 0x040019AD RID: 6573
	public SimpleFade.Fade _Fade;

	// Token: 0x040019AE RID: 6574
	public float _Time = 1f;

	// Token: 0x040019AF RID: 6575
	public Color _Color = Color.white;

	// Token: 0x040019B0 RID: 6576
	public Texture2D _Texture;

	// Token: 0x040019B1 RID: 6577
	protected float timer;

	// Token: 0x040019B2 RID: 6578
	private SimpleFade.FadeInOut fadeInOut;

	// Token: 0x02000362 RID: 866
	public enum Fade
	{
		// Token: 0x040019B4 RID: 6580
		In,
		// Token: 0x040019B5 RID: 6581
		Out
	}

	// Token: 0x02000363 RID: 867
	public class FadeInOut
	{
		// Token: 0x0600159C RID: 5532 RVA: 0x00092A74 File Offset: 0x00090C74
		public FadeInOut()
		{
		}

		// Token: 0x0600159D RID: 5533 RVA: 0x00092AB4 File Offset: 0x00090CB4
		public FadeInOut(SimpleFade fade)
		{
			this.inTime = (this.outTime = fade._Time);
			this.inColor = (this.outColor = fade._Color);
		}

		// Token: 0x0600159E RID: 5534 RVA: 0x00092B28 File Offset: 0x00090D28
		public bool Update()
		{
			this.timer = Mathf.Min(this.timer + Time.unscaledDeltaTime, this.waitTime);
			return this.timer == this.waitTime;
		}

		// Token: 0x040019B6 RID: 6582
		public float inTime = 1f;

		// Token: 0x040019B7 RID: 6583
		public float outTime = 1f;

		// Token: 0x040019B8 RID: 6584
		public Color inColor = Color.white;

		// Token: 0x040019B9 RID: 6585
		public Color outColor = Color.white;

		// Token: 0x040019BA RID: 6586
		public float waitTime = 1f;

		// Token: 0x040019BB RID: 6587
		private float timer;
	}
}
